﻿<?php
session_start();

//Pear & Propel Stuffs
set_include_path(get_include_path() .PATH_SEPARATOR. "../../../libs/pear");
set_include_path(get_include_path() .PATH_SEPARATOR. "../../../libs/propel/runtime/lib");
set_include_path(get_include_path() .PATH_SEPARATOR. "../../../bdd/build/classes");
require_once '../../../libs/propel/runtime/lib/Propel.php';
Propel::init("../../../bdd/build/conf/tshirtfactory-conf.php");

include "../../../pages/classes/ArticleCart.php";


//Get Disponibility
$d = DisponibiliteQuery::create()->filterByShirtId($_GET['id'])->filterByCouleur($_GET['color'])->filterBySexe($_GET['sex'])->filterByTaille($_GET['size'])->findOne();
$stock = ($d != null)?($d->getQuantite()):0;

if($stock >= $_GET['quantity'])
{
	array_push($_SESSION['cart'], serialize(ArticleCart::create($_GET['id'], $_GET['quantity'], $_GET['size'], $_GET['color'], $_GET['sex'])));
	echo "1;".count($_SESSION['cart']);	//Ok
}
else
{
	echo "0;".$stock;	//Unable to buy the product: display amount of remaining shirt in the database
}